package com.carbonxsilicon.travellersbuddy;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;


import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.fima.cardsui.objects.CardStack;
import com.fima.cardsui.views.CardUI;

public class ProfileActivity extends Activity {

    private CardUI mCardViewAbove, mCardView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_profile);

        String name = "Cosmin Dragomir";

        TextView tv_name = (TextView) findViewById(R.id.name);
        tv_name.setText(name);

        mCardViewAbove = (CardUI) findViewById(R.id.cardsviewabove);
        mCardViewAbove.setSwipeable(false);
        CardStack stack2 = new CardStack();
        stack2.setTitle("PHOTOS");
        mCardViewAbove.addStack(stack2);


        int picturesNo = 5;
        Drawable[] drawables = new Drawable[picturesNo];


        LinearLayout layout = (LinearLayout)findViewById(R.id.column);
        //Field[] drawables = android.R.drawable.class.getFields();
        Drawable picture;
        picture = getResources().getDrawable( R.drawable.sample_0);
        drawGallery(layout, picture);
        picture = getResources().getDrawable( R.drawable.sample_1);
        drawGallery(layout, picture);
        picture = getResources().getDrawable( R.drawable.sample_2);
        drawGallery(layout, picture);
        picture = getResources().getDrawable( R.drawable.sample_3);
        drawGallery(layout, picture);
        picture = getResources().getDrawable( R.drawable.sample_4);
        drawGallery(layout, picture);






        // The ABOUT section of the profile
        mCardView = (CardUI) findViewById(R.id.cardsviewbelow);
        mCardView.setSwipeable(false);


        CardStack stackPlay = new CardStack();
        stackPlay.setTitle("ABOUT");
        mCardView.addStack(stackPlay);

        //just some hardcode strings for testing
        String age = "21";
        String birthday = "23 November 1991";
        String gender = "Male";
        String nationality = "Romanian";
        String location = "London";
        String[] languages = {"Romanian", "English", "Spanish"};

        //Constructing the known languages string
        String knownLanguages = "";
        String dummyKnownLanguages = "";
        for (String l : languages) {
            dummyKnownLanguages += l + ", ";
        }

        if (dummyKnownLanguages != "") {
            knownLanguages = dummyKnownLanguages.substring(0,dummyKnownLanguages.length() - 2) + ".";
        }

        //Adding the cards to the UI
        mCardView.addCard(new MyCard("Basic Information","<b>Age:</b>\t\t\t\t\t" + age + "<br>" +
                "<b>Birthday:</b>\t\t\t" + birthday + "<br>" + "<b>Gender:</b>\t\t\t" + gender, false));

        mCardView.addCard(new MyCard("Travelling Information", "<b>Nationality:</b>\t\t" + nationality + "<br>" +
                "<b>Location:</b>\t\t" + location + "<br>" + "<b>Languages:</b>\t" + knownLanguages , true));


        //Draw cards
        mCardViewAbove.refresh();
        mCardView.refresh();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.profile, menu);
        return true;
    }

    public void drawGallery(LinearLayout layout, Drawable picture) {
        ImageView imView = new ImageView(getApplicationContext());
        imView.setImageDrawable(picture);
        imView.setPadding(8, 8, 0, 0);
        imView.setLayoutParams(new LinearLayout.LayoutParams(250,250));
        layout.addView(imView);
    }



}
